package com.zhbcm.outupload.web;

import com.zhbcm.outupload.utils.UploadFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 朝花不迟暮
 * @version 1.0
 * @date 2021/6/26 20:25
 */
@RestController
public class FileController
{
    @Autowired
    private UploadFileUtil uploadFileUtil;

    @PostMapping("/upload")
    public String upload(MultipartFile file, HttpServletRequest req)
    {
        return uploadFileUtil.upload(file, req);
    }

    @GetMapping("/")
    public void download(String url, HttpServletResponse res)
    {
        uploadFileUtil.downloadImg(url, res);
    }
}
